package util.enumhelper;

import entity.AnalyticsEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import org.primefaces.model.chart.ChartModel;
import java.util.List;
import javax.faces.model.SelectItem;

public class MetricHelper implements Serializable{
    //chart to be displayed
    private ChartModel model;
    private String name;
    private int chartType;
    private String description;
    //this variable is used to retrieve all the selection
    //lists
    private int getSelectList;
    //selection list
    private List<List<SelectItem>> selectList;
    //name for each selection list
    private List<String> selectListName;
    //used to set each select var
    private int setSelectVar;
    //used to get each select var
    private int getSelectVar;
    //list of variables assigned for each selection list
    private List<Integer> selectVar;
    //list of variables input by user
    private List<Integer> var;
    //name of variables input by user
    private List<String> varName;
    private int setVar;
    private int getVar;
    //dataTable to be displayed
    private List<List<SpecialType>> dataTable;
    private List<String> dataTableName;
    private int getDataTable;
    //list of date selected by calendars
    private List<Date> dateList;
    //name of each date selected
    private List<String> dateListName;
    private int getDateList;
    private int setDateList;
    //whether the user can input number to change the content
    //of this metric or not
    private boolean compute;
    //whether this metric is initialized all attributes or not
    private boolean init;
    private List<String> outputValue;
    private List<String> outputValueName;
    private int getOutputValue;
    private int previousValue;

    public MetricHelper(AnalyticsEntity ana) {
        selectList = new ArrayList<List<SelectItem>>();
        selectListName = new ArrayList<String>();
        selectVar = new ArrayList<Integer>();
        dateList = new ArrayList<Date>();
        dateListName = new ArrayList<String>();
        var = new ArrayList<Integer>();
        varName = new ArrayList<String>();
        outputValue = new ArrayList<String>();
        outputValueName = new ArrayList<String>();
        dataTable = new ArrayList<List<SpecialType>>();
        dataTableName = new ArrayList<String>();
        this.name = ana.getName();
        String type = ana.getChartType();
        if (type == null)
            chartType = 0;
        else if (type.equals("PieChart"))
            chartType = 1;
        else if (type.equals("BarChart"))
            chartType = 2;
        else if (type.equals("LineChart"))
            chartType = 3;
        else if (type.equals("ColmunChart"))
            chartType = 4;
        this.description = ana.getDescription();
        compute = false;
        previousValue = - 1;
    }

    public ChartModel getModel() {
        return model;
    }

    public void setModel(ChartModel model) {
        this.model = model;
    }

    public void setSelectVar(int value) {
        selectVar.set(setSelectVar, value);
        setSelectVar = (setSelectVar + 1) % selectVar.size();
    }

    public int getSelectVar() {
        int temp = selectVar.get(getSelectVar);
        getSelectVar = (getSelectVar + 1) % selectVar.size();
        return temp;
    }

    public void setVar(int value) {
        var.set(setVar, value);
        setVar = (setVar + 1) % var.size();
    }

    public int getVar() {
        int temp = var.get(getVar);
        getVar = (getVar + 1) % var.size();
        return temp;
    }
    
    public String getVarName() {
        return varName.get(getVar);
    }

    public void addVar(String name) {
        var.add(0);
        varName.add(name);
    }

    public List<SpecialType> getDataTable(int pos) {
        /*
        List<SpecialType> list = dataTable.get(getDataTable);
        getDataTable = (getDataTable+1)% dataTable.size();
        return list;
         * 
         */
        return dataTable.get(pos);
    }
    
    public String getDataTableName(int pos) {
        return dataTableName.get(pos);
    }

    public void addDataTable(List<SpecialType> table, String name) {
        dataTable.add(table);
        dataTableName.add(name);
    }
    
    public int getDataTableSize() {
        return dataTable.size();
    }

    public boolean isCompute() {
        return compute;
    }

    public void setCompute(boolean compute) {
        this.compute = compute;
    }

    public List<SelectItem> getSelectList() {
        List<SelectItem> temp = selectList.get(getSelectList);
        getSelectList = (getSelectList+1)%selectList.size();
        return temp;
    }

    public void addSelectList(List<SelectItem> list, String name) {
        this.selectList.add(list);
        selectVar.add(0);
        selectListName.add(name);
    }
    
    public String getSelectListName() {
        return selectListName.get(getSelectList);
    }
    
    public void addDateList(String name) {
        dateList.add(new Date());
        dateListName.add(name);
    }
    
    public Date getDateList() {
        Date date = dateList.get(getDateList);
        getDateList = (getDateList+1)%dateList.size();
        return date;
    }
    
    public String getDateListName() {
        return dateListName.get(getDateList);
    }
    
    public void setDateList(Date date) {
        dateList.set(setDateList, date);
        setDateList = (setDateList+1)% dateList.size();
    }
    
    public int getDateListSize() {
        return dateList.size();
    }
    
    public int getSelectListSize() {
        return selectList.size();
    }
    
    public int getVarSize() {
        return var.size();
    }

    public String getName() {
        return name;
    }

    public int getChartType() {
        return chartType;
    }

    public String getDescription() {
        return description;
    }

    public boolean isInit() {
        return init;
    }

    public void setInit(boolean init) {
        this.init = init;
    }
    
    public void addOutputValue(String name, String value) {
        outputValue.add(value);
        outputValueName.add(name);
    }
    
    public String getOutputValueName() {
        return outputValueName.get(getOutputValue);        
    }
    
    public String getOutputValue() {
        String temp = outputValue.get(getOutputValue);
        getOutputValue = (getOutputValue+1)%outputValue.size();
        return temp;
    }
    
    public int getOutputValueSize() {
        return outputValue.size();
    }
    
    public void resetDataTable() {
        dataTable = new ArrayList<List<SpecialType>>();
        dataTableName = new ArrayList<String>();
    }
    
    public void resetDateList() {
        dateList = new ArrayList<Date>();
        dateListName = new ArrayList<String>();
    }
    
    public void resetOutputValue() {
        outputValue = new ArrayList<String>();
        outputValueName = new ArrayList<String>();
    }

    public int getPreviousValue() {
        return previousValue;
    }

    public void setPreviousValue(int previousValue) {
        this.previousValue = previousValue;
    }
}
